﻿CREATE PROCEDURE [dbo].[sp_ConfigureCommittee]
	@CommitteeName NVarChar(50),
	@IsMainCommittee bit,
	@CommID uniqueidentifier OUTPUT
AS

	
	IF @IsMainCommittee = 0
	begin 
		SET @CommID = NewID()

		INSERT INTO Sync.Peers(CommitteId,LastSyncVersion,LastSyncDateTime)
		values( 'BF857B8A-AA50-4B22-88F0-D657368182D8',NULL,NULL)
	end 
	ELSE
		SET @CommID = 'BF857B8A-AA50-4B22-88F0-D657368182D8'

	DECLARE @CommitteeBankAccountID uniqueidentifier
	DECLARE @CommitteeBankAccountID1 uniqueidentifier
	SET @CommitteeBankAccountID = NewID()
	SET @CommitteeBankAccountID1 = NewID()

	
	
	INSERT INTO dbo.Committees (CommitteeID, CommitteeName, CenterID,IsMainCommittee)
	VALUES (@CommID,@CommitteeName, '00000000-0000-0000-1111-000000000000',@IsMainCommittee)
	
	INSERT INTO [dbo].[CommittessVillages]([CommitteID], [VillageID])
    VALUES (@CommID, '00000000-0000-0000-1111-000000000000')


	Update [Settings] set [CommitteeID] = @CommID

	INSERT INTO dbo.UsersCommittees (UserID, CommitteeID)
	VALUES ('00000000-0000-0000-1111-000000000000', @CommID)


	INSERT INTO [CommitteeBankAccount]
           ([CommitteeBankAccountID]
           ,[CommitteeID]
           ,[BankAccountNumber]
           ,[ProjectID])
     VALUES
           (@CommitteeBankAccountID,
			@CommID,
           1,
           '00000000-0000-1111-0000-000000000000');
INSERT INTO [CommitteeBankAccount]
           ([CommitteeBankAccountID]
           ,[CommitteeID]
           ,[BankAccountNumber]
           ,[ProjectID])
     VALUES
           (@CommitteeBankAccountID1,
			@CommID,
           2,
           '00000000-0000-0000-1111-000000000000');


INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
           (N'AllowedDiscreteDelay', 10, @CommID, NEWID())
           
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
           (N'AllowedConsecutiveDelay', 10, @CommID, NEWID())
           
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
           (N'AllowedDaysFromLastClosedLoan', 10, @CommID, NEWID())
           
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
           (N'FeasibilityStudyTaxes', 10, @CommID, NEWID())

INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'ReceiptSeed', '100' ,@CommID ,NEWID());

INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'ReceipteImagePath', 'C:\Users\Public\Pictures\Sample Pictures\Koala.jpg', @CommID, NEWID());
			
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'NewLoanReceiptAmount', '5', @CommID,	NEWID());
			
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'AutomaticCloseDay', '12', @CommID,	NEWID());
						
INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'PeriodBeforeEndStuckLoan', '6', @CommID,	NEWID());

INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'MaxAllowedPostponeMonths', '6', @CommID,	NEWID());


INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'DatabaseBackupTime', '5:00 am', @CommID,	NEWID());

INSERT INTO [Settings]([Key],[Value],[CommitteeID],[ID])
     VALUES
			(N'DatabaseSynchTime', '1:00 am', @CommID,	NEWID());

RETURN 0